//
//  PurlistInformationViewModel.m
//  GLGW_Shoping
//
//  Created by yang on 2018/12/10.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "PurlistInformationViewModel.h"
#import "ConfirmGoodsTableViewCell.h"
#import "RequirementsTableViewCell.h"
#import "NoDataFootTableViewHeaderFooterView.h"
#import "FreeGoodsInforBottomView.h"
#import "PurListBaoJiaInforTableViewCell.h"
#import "PurListInformationLastTableViewCell.h"
#import "PopupView.h"
#import "SharePopView.h"
#import "PurInformationHeaderView.h"
#import "ConfirmTopTimeView.h"

@interface PurlistInformationViewModel ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation PurlistInformationViewModel

-(instancetype)initWithViewToViewModel:(UITableView *)tableView theSuperView:(UIView *)superView{
    if (self = [super initWithViewToViewModel:tableView theSuperView:superView]) {
        tableView.y = tableView.y+ kHeightProportion_In_iPhoneTriploid(30);
        tableView.height = tableView.height - kHeightProportion_In_iPhoneTriploid(90);
        tableView.mj_header.hidden = YES;
        tableView.mj_footer.hidden = YES;
        tableView.delegate = self;
        tableView.dataSource = self;
        [tableView registerClass:[NoDataFootTableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:@"NoDataFootTableViewHeaderFooterView"];
        //定金求购需要加头部
        tableView.tableHeaderView = [self createHeaderView];
        [superView addSubview:tableView];
        //
        ConfirmTopTimeView * confirmView = [[ConfirmTopTimeView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, kHeightProportion_In_iPhoneTriploid(30)) inSuperView:superView];
        //
        FreeGoodsInforBottomView * bottomView = [[FreeGoodsInforBottomView alloc] initWithFrame:CGRectMake(0, kY_With_View(tableView, 0), KScreenWidth, kHeightProportion_In_iPhoneTriploid(60)) inSuperView:superView];
        bottomView.b_type = BaoJiaType_BaoJia;
        bottomView.Block_FreeGoodsInfor = ^(GLGWButton * _Nonnull f_but) {
            if (f_but.tag == 300) {//我要报价
                if (self.delegate && [self.delegate respondsToSelector:@selector(goBaoJiaAction)]) {
                    [self.delegate goBaoJiaAction];
                }
            }else if (f_but.tag == 301){//分享
                SharePopView * shareView = [[SharePopView alloc] initWithSharePopView];
                shareView.Block_ShareAction = ^(GLGWButton * _Nonnull senderBut) {
                    if (senderBut.tag == 102) {
                        if (self.delegate && [self.delegate respondsToSelector:@selector(shareOneManAction)]) {
                            [self.delegate shareOneManAction];
                        }
                    }
                };
            }else{//联系
                PopupView * popselectView = [[PopupView alloc] initPopupview:@[@"拨打电话给",@"张三"]];
                popselectView.haveTitle = YES;
            }
        };
    }
    return self;
}

-(UIView *)createHeaderView{
    PurInformationHeaderView * headerView = [[PurInformationHeaderView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, kHeightProportion_In_iPhoneTriploid(62))];
    return headerView;
}

#pragma mark --UITableViewDataSource,UITableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 3;
    }else{
        return 3;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat cellHeight = kHeightProportion_In_iPhoneTriploid(107);
    if (indexPath.section == 1) {
        switch (indexPath.row) {
            case 0:{
                cellHeight = kHeightProportion_In_iPhoneTriploid(80);
            }
                break;
            case 1:{
                 cellHeight = kHeightProportion_In_iPhoneTriploid(110);
            }
                break;
            case 2:{
                 cellHeight = kHeightProportion_In_iPhoneTriploid(132);
            }
                break;
                
            default:
                break;
        }
    }
    return cellHeight;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    BaseTableViewCell * cell;
    if (indexPath.section == 0) {
        ConfirmGoodsTableViewCell * cell_goods = [ConfirmGoodsTableViewCell cellWithTableView:tableView];
        cell = cell_goods;
    }else{
        switch (indexPath.row) {
            case 0:{
                RequirementsTableViewCell * cell_req = [RequirementsTableViewCell cellWithTableView:tableView];
                cell = cell_req;
            }
                break;
            case 1:{
                PurListInformationLastTableViewCell * cell_infor = [PurListInformationLastTableViewCell cellWithTableView:tableView];
                cell = cell_infor;
                
            }
                break;
            case 2:{
                PurListBaoJiaInforTableViewCell * cell_baojia = [PurListBaoJiaInforTableViewCell cellWithTableView:tableView];
                cell = cell_baojia;
            }
                break;
                
            default:
                break;
        }
    }
    return cell;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    NoDataFootTableViewHeaderFooterView * headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"NoDataFootTableViewHeaderFooterView"];
    headerView.bgColor = [UIColor whiteColor];
    return headerView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return kHeightProportion_In_iPhoneTriploid(10);
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    NoDataFootTableViewHeaderFooterView * footerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"NoDataFootTableViewHeaderFooterView"];
    footerView.bgColor = [UIColor colorWithHexString:@"#F2F2F2"];
    return footerView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 1) {
        return kHeightProportion_In_iPhoneTriploid(10);
    }else{
        return 0.01;
    }
}

@end
